package com.ruoyi.web.controller.xiaomi;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.bye.xiaomi_mall.domain.TdGoodsCategory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.bye.xiaomi_mall.domain.TdRotateImage;
import com.bye.xiaomi_mall.service.ITdRotateImageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播图Controller
 *
 * @author ruoyi
 * @date 2025-03-16
 */
@RestController
@RequestMapping("/xiaomi_mall/image")
public class TdRotateImageController extends BaseController {
    @Autowired
    private ITdRotateImageService tdRotateImageService;


    /**
     * 查询轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('xiaomi_mall:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(TdRotateImage tdRotateImage) {
        startPage();
        List<TdRotateImage> list = tdRotateImageService.selectTdRotateImageList(tdRotateImage);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('xiaomi_mall:image:export')")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdRotateImage tdRotateImage) {
        List<TdRotateImage> list = tdRotateImageService.selectTdRotateImageList(tdRotateImage);
        ExcelUtil<TdRotateImage> util = new ExcelUtil<TdRotateImage>(TdRotateImage.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('xiaomi_mall:image:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tdRotateImageService.selectTdRotateImageById(id));
    }

    /**
     * 新增轮播图
     */
    @PreAuthorize("@ss.hasPermi('xiaomi_mall:image:add')")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdRotateImage tdRotateImage) {
        return toAjax(tdRotateImageService.insertTdRotateImage(tdRotateImage));
    }

    /**
     * 修改轮播图
     */
    @PreAuthorize("@ss.hasPermi('xiaomi_mall:image:edit')")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdRotateImage tdRotateImage) {
        return toAjax(tdRotateImageService.updateTdRotateImage(tdRotateImage));
    }

    /**
     * 删除轮播图
     */
    @PreAuthorize("@ss.hasPermi('xiaomi_mall:image:remove')")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tdRotateImageService.deleteTdRotateImageByIds(ids));
    }
}
